#!/usr/local/bin/perl

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use DBI;
use IO::String;
use Bio::SeqIO;
use BioProof;
use Error qw(:try);

my $seqStr = param('data');
my $verify = param('verify');
my $keywords = param('keywords');
my $primers = param('primers');
my $primer5 = param('primer5');
my $primer3 = param('primer3');
my $codons = param('codons');
my $email = param('email');
my $name = param('name');
my $codontable = param('codontable');

my $proofer = new BioProof($verify,$primers,$codons);
$proofer->AddEmail($email);
$proofer->AddName($name);
$proofer->AddPrimers($primer3,$primer5);
$proofer->AddData($seqStr);
$proofer->AddCodonTable($codontable);
$proofer->AddKeywords($keywords);


my @cor = $proofer->IsCorrect();
if($#cor != -1){
	print header;
	print start_html("Error in submission");
	print "There were errors in the submission.  Please <a href=\"index.html\">return</a> and correct them:\n";
	print "<ul>\n";
	foreach(@cor){
		print "<li>$_</li>\n";
	}
	print "</ul>\n";
	print end_html;
} else {
	my $id = $proofer->AddToDB;
	my $dir = "tmp/job_$id/";
	my $file = "results.html";
	system("cp",$file,$dir);
	system("chmod","777","$dir$file");
	
	print "Location: tmp/job_$id/results.html\n\n";
}
